package org.wmq.taskschedule.algorithm;

import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

/**
 * 双边滤波算法执行器
 * 实现AlgorithmExecutor接口，用于对图像进行双边滤波处理
 */
public class BilateralFilterExecutor implements AlgorithmExecutor {

    private int diameter; // 过滤期间使用的每个像素邻域的直径
    private double sigmaColor; // 颜色空间中的sigma值
    private double sigmaSpace; // 坐标空间中的sigma值
    private String description; // 算法描述

    /**
     * 默认构造函数，使用默认参数
     */
    public BilateralFilterExecutor() {
        this.diameter = 9;
        this.sigmaColor = 75;
        this.sigmaSpace = 75;
        this.description = "双边滤波算法 - 在保持边缘的同时平滑图像";
    }

    /**
     * 构造函数，允许自定义参数
     * 
     * @param diameter 过滤期间使用的每个像素邻域的直径
     * @param sigmaColor 颜色空间中的sigma值
     * @param sigmaSpace 坐标空间中的sigma值
     */
    public BilateralFilterExecutor(int diameter, double sigmaColor, double sigmaSpace) {
        this.diameter = diameter;
        this.sigmaColor = sigmaColor;
        this.sigmaSpace = sigmaSpace;
        this.description = "双边滤波算法 - 在保持边缘的同时平滑图像";
    }

    /**
     * 构造函数，允许自定义所有参数
     * 
     * @param diameter 过滤期间使用的每个像素邻域的直径
     * @param sigmaColor 颜色空间中的sigma值
     * @param sigmaSpace 坐标空间中的sigma值
     * @param description 算法描述
     */
    public BilateralFilterExecutor(int diameter, double sigmaColor, double sigmaSpace, String description) {
        this.diameter = diameter;
        this.sigmaColor = sigmaColor;
        this.sigmaSpace = sigmaSpace;
        this.description = description;
    }

    @Override
    public Mat execute(Mat input) {
        if (input == null || input.empty()) {
            throw new IllegalArgumentException("输入图像不能为空");
        }

        // 创建输出图像
        Mat output = new Mat();

        // 应用双边滤波算法
        Imgproc.bilateralFilter(input, output, diameter, sigmaColor, sigmaSpace);

        return output;
    }

    // Getters and setters
    public int getDiameter() {
        return diameter;
    }

    public void setDiameter(int diameter) {
        this.diameter = diameter;
    }

    public double getSigmaColor() {
        return sigmaColor;
    }

    public void setSigmaColor(double sigmaColor) {
        this.sigmaColor = sigmaColor;
    }

    public double getSigmaSpace() {
        return sigmaSpace;
    }

    public void setSigmaSpace(double sigmaSpace) {
        this.sigmaSpace = sigmaSpace;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}